//引入Vue
import Vue from "vue";
//引入vue-router路由插件
import VueRouter from "vue-router";
// 使用插件
Vue.use(VueRouter);

// 修正Vue原型上的push和replace方法 start

// 缓存原型上的push函数
const originPush = VueRouter.prototype.push;
const originReplace = VueRouter.prototype.replace;
// 给原型对象上的push指定新函数函数
VueRouter.prototype.push = function ( to, onComplete, onAbort ) {
  if (onComplete && onAbort) {
    originPush.call(this, to, onComplete, onAbort)
  } else {
    originPush.call(this, to,
      () => {
        console.log("[push]跳转成功:", to)
      },
      () => {
        console.error("[push]跳转失败:", to)

      })
  }
}
VueRouter.prototype.replace = function ( to, onComplete, onAbort ) {
  if (onComplete && onAbort) {
    originReplace.call(this, to, onComplete, onAbort)
  } else {
    originReplace.call(this, to,
      () => {
        console.log("[replace]跳转成功:", to)
      },
      () => {
        console.error("[replace]跳转失败:", to)

      })
  }
}
// 修正Vue原型上的push和replace方法 end


const routes = [
  {
    path: "/",
    redirect: "/home"
  },
  {
    path: "/home",
    component: () => import("@/pages/Home"),
    meta: { isShowFooter: true }
  },
  {
    path: "/search",
    component: () => import("@/pages/Search"),
    meta: { isShowFooter: false }
  },
  {
    path: "/register",
    component: () => import("@/pages/Register"),
    meta: { isShowFooter: false }
  },
  {
    path: "/login",
    component: () => import("@/pages/Login"),
    meta: { isShowFooter: false }
  },
];


export default new VueRouter({
  routes // (缩写) 相当于 routes: routes
})
